<template>
	<div>
		<el-form ref="form" :model="form" label-width="80px">
			<el-form-item label="入库日期">
				<el-date-picker
				      size="mini"
				      v-model="form.inst_store_date"
					  value-format="yyyy-MM-dd"
				      type="date"
				      placeholder="选择日期时间">
				</el-date-picker>
			</el-form-item>
			<el-form-item label="发生日期">
				<el-date-picker
				      size="mini"
				      v-model="form.buyer_date"
					  value-format="yyyy-MM-dd"
				      type="date"
				      placeholder="选择日期时间">
				</el-date-picker>
			</el-form-item>
			<el-form-item label="商品名称">
			   <selectGoods @getGoodsData="getGoodsData" :scopeData="{}" />
			</el-form-item>
			<el-form-item label="成本单价">
			    <el-input size="mini" style="width: 300px;"  v-model="form.price"></el-input>
			</el-form-item>
			<el-form-item label="">
			    <el-button type="primary"
					@click="confirm"
					:loading="loading_btn"
					size="mini">确定</el-button>
			</el-form-item>
		</el-form>	
	</div>
</template>

<script>
	import selectGoods from "@/components/selectGoods"
	export default {
		components:{
			selectGoods
		},
		data(){
			return {
				form:{
					inst_store_date:"",
					buyer_date:"",
					price:"",
					goods_name:""
				}
			}
		},
		mounted() {
			this.form.inst_store_date = this.$utils.formatNowDate(2)
			this.form.buyer_date = this.$utils.formatNowDate(2)
		},
		methods:{
			getGoodsData(val){
				this.form.goods_name = val.goods_name
			},
			confirm(){
				if(!this.form.inst_store_date) return this.$message.error('请选择入库日期')
				if(!this.form.buyer_date) return this.$message.error('请选择发生日期')
				if(!this.form.goods_name) return this.$message.error('请选择商品')
				if(!this.form.price) return this.$message.error('请输入成本单价')
				
				this.form.cid = sessionStorage.getItem('cid')
				let arr = [this.form]
				
				this.$post('/buyerSys/setHsPrice',arr,res=>{
					this.$message.success('操作成功')
					this.$emit('addHsSuccess')
				})
				
			},
		}
	}
</script>

<style>
</style>